package com.crm.model.pojo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fasterxml.jackson.annotation.JsonIgnore;


/**
 * The persistent class for the sales_opportunities database table.
 * [-
 */
@Entity
@Table(name="sales_opportunities")
@NamedQuery(name="SalesOpportunity.findAll", query="SELECT s FROM SalesOpportunity s")
public class SalesOpportunity implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="sal_id")
	private int salId;//销售机会id

	@Lob
	@Column(name="cust_demand")
	private String custDemand;//客户需求

	@Lob
	@Column(name="sal_file")
	private String salFile;//上传附件

	@Column(name="sal_possibility")
	private Integer salPossibility;//可能性

	@Column(name="sal_source")
	private Integer salSource;//客户来源

	@Column(name="sal_stage")
	private Integer salStage;//销售阶段

	@Lob
	@Column(name="sal_stage_notes")
	private String salStageNotes;//阶段备注

	@Column(name="sal_stage_stop")
	private Integer salStageStop;//阶段停留

	@Column(name="sal_state")
	private Integer salState;//销售状态

	@Column(name="sal_theme")
	private String salTheme;//销售机会名称

	@Column(name="sal_type")
	private Integer salType;//销售机会类型

	@Temporal(TemporalType.DATE)
	@Column(name="sal_updatetime")
	private Date salUpdatetime;//销售机会的更新时间

	@Temporal(TemporalType.DATE)
	@Column(name="sotl_date")
	private Date sotlDate;//预计签单日期

	@Column(name="sotl_id")
	private Integer sotlId;//机会负责人编号

	@Column(name="sotl_money")
	private BigDecimal sotlMoney;//预期金额

	@Column(name="star_standard")
	private Integer starStandard;//星标,用不同颜色表示,默认为无
	
	private Integer state;//判断是否可用

	//bi-directional many-to-one association to Competitor
	@OneToMany(mappedBy="salesOpportunity")
	private List<Competitor> competitors;

	//bi-directional many-to-one association to DetailedDemand
	@JsonIgnore
	@OneToMany(mappedBy="salesOpportunity")
	private List<DetailedDemand> detailedDemands;

	//bi-directional many-to-one association to Orderinfo
	@JsonIgnore
	@OneToMany(mappedBy="salesOpportunity")
	private List<Orderinfo> orderinfos;

	//bi-directional many-to-one association to QuotationRecord
	@JsonIgnore
	@OneToMany(mappedBy="salesOpportunity")
	private List<QuotationRecord> quotationRecords;

	//bi-directional many-to-one association to Customer
	@ManyToOne
	@JoinColumn(name="cust_id")
	private Customer customer;

	//bi-directional many-to-one association to Contact
	@ManyToOne
	@JoinColumn(name="con_id")
	private Contact contact;

	//bi-directional many-to-one association to SalesOpportunityTrackingLog
	@JsonIgnore
	@OneToMany(mappedBy="salesOpportunity")
	private List<SalesOpportunityTrackingLog> salesOpportunityTrackingLogs;

	//bi-directional many-to-one association to Solution
	@JsonIgnore
	@OneToMany(mappedBy="salesOpportunity")
	private List<Solution> solutions;

	public SalesOpportunity() {
	}

	public Integer getSalId() {
		return this.salId;
	}

	public void setSalId(Integer salId) {
		this.salId = salId;
	}

	public String getCustDemand() {
		return this.custDemand;
	}

	public void setCustDemand(String custDemand) {
		this.custDemand = custDemand;
	}

	public String getSalFile() {
		return this.salFile;
	}

	public void setSalFile(String salFile) {
		this.salFile = salFile;
	}

	public Integer getSalPossibility() {
		return this.salPossibility;
	}

	public void setSalPossibility(Integer salPossibility) {
		this.salPossibility = salPossibility;
	}

	public Integer getSalSource() {
		return this.salSource;
	}

	public void setSalSource(Integer salSource) {
		this.salSource = salSource;
	}

	public Integer getSalStage() {
		return this.salStage;
	}

	public void setSalStage(Integer salStage) {
		this.salStage = salStage;
	}

	public String getSalStageNotes() {
		return this.salStageNotes;
	}

	public void setSalStageNotes(String salStageNotes) {
		this.salStageNotes = salStageNotes;
	}

	public Integer getSalStageStop() {
		return this.salStageStop;
	}

	public void setSalStageStop(Integer salStageStop) {
		this.salStageStop = salStageStop;
	}

	public Integer getSalState() {
		return this.salState;
	}

	public void setSalState(Integer salState) {
		this.salState = salState;
	}

	public String getSalTheme() {
		return this.salTheme;
	}

	public void setSalTheme(String salTheme) {
		this.salTheme = salTheme;
	}

	public Integer getSalType() {
		return this.salType;
	}

	public void setSalType(Integer salType) {
		this.salType = salType;
	}

	public Date getSalUpdatetime() {
		return this.salUpdatetime;
	}

	public void setSalUpdatetime(Date salUpdatetime) {
		this.salUpdatetime = salUpdatetime;
	}

	public Date getSotlDate() {
		return this.sotlDate;
	}

	public void setSotlDate(Date sotlDate) {
		this.sotlDate = sotlDate;
	}

	public Integer getSotlId() {
		return this.sotlId;
	}

	public void setSotlId(Integer sotlId) {
		this.sotlId = sotlId;
	}

	public BigDecimal getSotlMoney() {
		return this.sotlMoney;
	}

	public void setSotlMoney(BigDecimal sotlMoney) {
		this.sotlMoney = sotlMoney;
	}

	public Integer getStarStandard() {
		return this.starStandard;
	}

	public void setStarStandard(Integer starStandard) {
		this.starStandard = starStandard;
	}

	public List<Competitor> getCompetitors() {
		return this.competitors;
	}

	public void setCompetitors(List<Competitor> competitors) {
		this.competitors = competitors;
	}

	public Competitor addCompetitor(Competitor competitor) {
		getCompetitors().add(competitor);
		competitor.setSalesOpportunity(this);

		return competitor;
	}

	public Competitor removeCompetitor(Competitor competitor) {
		getCompetitors().remove(competitor);
		competitor.setSalesOpportunity(null);

		return competitor;
	}

	public List<DetailedDemand> getDetailedDemands() {
		return this.detailedDemands;
	}

	public void setDetailedDemands(List<DetailedDemand> detailedDemands) {
		this.detailedDemands = detailedDemands;
	}

	public DetailedDemand addDetailedDemand(DetailedDemand detailedDemand) {
		getDetailedDemands().add(detailedDemand);
		detailedDemand.setSalesOpportunity(this);

		return detailedDemand;
	}

	public DetailedDemand removeDetailedDemand(DetailedDemand detailedDemand) {
		getDetailedDemands().remove(detailedDemand);
		detailedDemand.setSalesOpportunity(null);

		return detailedDemand;
	}

	public List<Orderinfo> getOrderinfos() {
		return this.orderinfos;
	}

	public void setOrderinfos(List<Orderinfo> orderinfos) {
		this.orderinfos = orderinfos;
	}

	public Orderinfo addOrderinfo(Orderinfo orderinfo) {
		getOrderinfos().add(orderinfo);
		orderinfo.setSalesOpportunity(this);

		return orderinfo;
	}

	public Orderinfo removeOrderinfo(Orderinfo orderinfo) {
		getOrderinfos().remove(orderinfo);
		orderinfo.setSalesOpportunity(null);

		return orderinfo;
	}

	public List<QuotationRecord> getQuotationRecords() {
		return this.quotationRecords;
	}

	public void setQuotationRecords(List<QuotationRecord> quotationRecords) {
		this.quotationRecords = quotationRecords;
	}

	public QuotationRecord addQuotationRecord(QuotationRecord quotationRecord) {
		getQuotationRecords().add(quotationRecord);
		quotationRecord.setSalesOpportunity(this);

		return quotationRecord;
	}

	public QuotationRecord removeQuotationRecord(QuotationRecord quotationRecord) {
		getQuotationRecords().remove(quotationRecord);
		quotationRecord.setSalesOpportunity(null);

		return quotationRecord;
	}

	public Customer getCustomer() {
		return this.customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Contact getContact() {
		return this.contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public List<SalesOpportunityTrackingLog> getSalesOpportunityTrackingLogs() {
		return this.salesOpportunityTrackingLogs;
	}

	public void setSalesOpportunityTrackingLogs(List<SalesOpportunityTrackingLog> salesOpportunityTrackingLogs) {
		this.salesOpportunityTrackingLogs = salesOpportunityTrackingLogs;
	}

	public SalesOpportunityTrackingLog addSalesOpportunityTrackingLog(SalesOpportunityTrackingLog salesOpportunityTrackingLog) {
		getSalesOpportunityTrackingLogs().add(salesOpportunityTrackingLog);
		salesOpportunityTrackingLog.setSalesOpportunity(this);

		return salesOpportunityTrackingLog;
	}

	public SalesOpportunityTrackingLog removeSalesOpportunityTrackingLog(SalesOpportunityTrackingLog salesOpportunityTrackingLog) {
		getSalesOpportunityTrackingLogs().remove(salesOpportunityTrackingLog);
		salesOpportunityTrackingLog.setSalesOpportunity(null);

		return salesOpportunityTrackingLog;
	}

	public List<Solution> getSolutions() {
		return this.solutions;
	}

	public void setSolutions(List<Solution> solutions) {
		this.solutions = solutions;
	}

	public Solution addSolution(Solution solution) {
		getSolutions().add(solution);
		solution.setSalesOpportunity(this);

		return solution;
	}

	public Solution removeSolution(Solution solution) {
		getSolutions().remove(solution);
		solution.setSalesOpportunity(null);

		return solution;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public void setSalId(int salId) {
		this.salId = salId;
	}
	
	/**
	 * 
	 * 自定义比较方法
	 * @param o
	 * @return
	 */
	public boolean equals(SalesOpportunity o) {

		if(null!=this.getSotlMoney()) {
			Double a=this.getSotlMoney().doubleValue();
			Double b=o.getSotlMoney().doubleValue();
			if(a!=b) {
				return false;
			}
		}
		if(this.getCustDemand()!=null&&(this.getCustDemand()!=o.getCustDemand())) {
			return false;
		}
		if(this.getSalFile()!=null&&(this.getSalFile()==o.getSalFile())) {
			return false;
		}
		if(this.getSalPossibility()!=null&&(this.getSalPossibility()==o.getSalPossibility())) {
			return false;
		}
		if(this.getSalSource()!=null&&(this.getSalSource()==o.getSalSource())) {
			return false;
		}
		if(this.getSalStage()!=null&&(this.getSalStage()==o.getSalStage())) {
			return false;
		}
		if(this.getSalStageNotes()!=null&&(this.getSalStageNotes()==o.getSalStageNotes())) {
			return false;
		}
		if(this.getSalState()!=null&&(this.getSalState()==o.getSalState())) {
			return false;
		}
		if(this.getSalTheme()!=null&&(this.getSalTheme()==o.getSalTheme())) {
			return false;
		}
		if(this.getSalType()!=null&&(this.getSalType()==o.getSalType())) {
			return false;
		}
		if(this.getSotlDate()!=null&&(this.getSotlDate()==o.getSotlDate())) {
			return false;
		}
		if(this.getStarStandard()!=null&&(this.getStarStandard()==o.getStarStandard())) {
			return false;
		}
		if(this.getSotlId()!=null&&(this.getSotlId()==o.getSotlId())) {
			return false;
		}

		return competitors.equals(o);
	}

}